package com.leave.service.Impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leave.dao.MenuMapper;
import com.leave.entity.Menu;
import com.leave.entity.Role;
import com.leave.service.IMenuService;

@Service
public class MenuServiceImpl implements IMenuService {
	@Autowired
	private MenuMapper menuMapper;
	
	public List<Menu> getMenuListByRoleName(String roleName) {
		List<Menu> menuList = menuMapper.getMenuListByRoleName(roleName);
		
		return menuList;
	}

	public HashMap<String, Object> getAllParentMenuByPage(Integer page, Integer rows) {
		PageHelper.startPage(page,rows);
		List<Menu> menuList = menuMapper.getAllParentMenu();
		PageInfo<Menu> pageInfo = new PageInfo<Menu>(menuList);
		Long total = pageInfo.getTotal();
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("menuList", menuList);
		map.put("total", total);
		return map;
	}

	public Menu getMenuByMenuId(int menuId) {
		return menuMapper.selectByPrimaryKey(menuId);
	}

	public int removeMenuByArrId(int[] arrId) {
		
		
		return menuMapper.deleteByArrId(arrId);
	}

	public int addMenu(Menu m) {
		
		return menuMapper.insertSelective(m);
	}

	public int updateMenuByMenu(Menu m) {
		return menuMapper.updateByPrimaryKeySelective(m);
	}

	public Menu getMenuByMenuName(String menuName) {
		// TODO Auto-generated method stub
		return menuMapper.getMenuByMenuName(menuName);
	}
	
	
}
